<template>
  <a-card :bordered="false">
    <!-- table区域-begin -->
    <div style="margin-bottom: 10px;">
      <span style="font-weight: bold">单据时间：</span>
      <a-checkable-tag style="font-size: 14px;margin: 5px;padding: 5px" v-for="(item,index) in this.receiptsDateList"
                       :key="index" v-model:checked="item.checkedValue"
                       @change="onChangeReceiptsDate(item.key,item.itemValue)">{{item.itemText}}
      </a-checkable-tag>
      <a-range-picker v-show="this.currentKey" @change="onChangeCustomerReceiptsDate" format="YYYY-MM-DD"
                      v-model:value="dateValue"/>
    </div>
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        :rowKey="(record,index)=>{return index}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <a slot="receiptsNo" slot-scope="text">{{ text }}</a>
      </a-table>
    </div>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import {filterObj} from '@/utils/util';
  import {mixinDevice} from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {getAction, putAction} from "@/api/manage";

  export default {
    name: "inventoryGatherList",
    mixins: [JeecgListMixin, mixinDevice],
    data() {
      return {
        description: '供应链采购订单表管理页面',
        currentKey: false,
        startDate: '',
        endDate: '',
        dateValue: [],
        supplierData: [],   //供应商列表
        depositoryData: [], //仓库列表
        purchasePeopleData: [],  //采购人员列表
        createByData: [],    //创建人列表
        model: {},
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '名称',
            align: "center",
            dataIndex: 'material.materialName'
          },
          {
            title: '型号',
            align: "center",
            dataIndex: 'material.modelNumber'
          },
          {
            title: '规格',
            align: "center",
            dataIndex: 'material.specifications'
          }, {
            title: '品牌',
            align: "center",
            dataIndex: 'material.brand'
          },
          {
            title: '市场价/元',
            align: "center",
            dataIndex: 'material.marketPrice',
            customRender: function (text) {
              if (text == null || text === 0){
                return "-"
              }else {
                return text
              }
            }
          },
          {
            title: '预算价/元',
            align: "center",
            dataIndex: 'material.estimatedCost',
            customRender: function (text) {
              if (text == null || text === 0){
                return "-"
              }else {
                return text
              }
            }
          },
          {
            title: '仓库',
            align: "center",
            dataIndex: 'depositoryName',
          },
          {
            title: '期初库存',
            align: "center",
            children: [
              {
                title: '数量',
                dataIndex: 'managePay',
                align: "center",
                customRender: function (text) {
                  return "-";
                }
              },
              {
                title: '成本',
                dataIndex: 'taxesPay',
                align: "center",
                customRender: function (text) {
                  return "-"
                }
              },
            ],
          },
          {
            title: '采购入库',
            align: "center",
            children: [
              {
                title: '数量',
                dataIndex: 'purchaseInDepositoryNum',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
              {
                title: '金额',
                dataIndex: 'purchaseInDepositoryMoney',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
            ],
          },
          {
            title: '其他入库',
            align: "center",
            children: [
              {
                title: '数量',
                dataIndex: 'otherInDepositoryNum',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
              {
                title: '金额',
                dataIndex: 'otherInDepositoryMoney',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
            ],
          },
          {
            title: '调拨入库',
            align: "center",
            children: [
              {
                title: '数量',
                dataIndex: 'allocateAndTransferInNum',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
            ],
          }, {
            title: '入库汇总',
            align: "center",
            dataIndex: 'inDepositoryTotalNum',
          }, {
            title: '采购退货',
            align: "center",
            children: [
              {
                title: '数量',
                dataIndex: 'purchaseGoodsRejectedNum',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
              {
                title: '金额',
                dataIndex: 'purchaseGoodsRejectedMoney',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
            ],
          },
          {
            title: '其他出库',
            align: "center",
            children: [
              {
                title: '数量',
                dataIndex: 'otherOutDepositoryNum',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
              {
                title: '金额',
                dataIndex: 'otherOutDepositoryMoney',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
            ],
          },
          {
            title: '调拨出库',
            align: "center",
            dataIndex: 'remark',
            children: [
              {
                title: '数量',
                dataIndex: 'allocateAndTransferOutNum',
                align: "center",
                customRender: function (text) {
                  return text == 0 ? "-":text;
                }
              },
            ],
          },
          {
            title: '出库汇总',
            align: "center",
            dataIndex: 'outDepositoryTotalNum'
          },
        ],

        url: {
          list: "/ghSupplychainDepositoryItem/inventoryGatherList",
          getSearchConditionData: "/ghSupplychainPurchaseOrder/getQueryCriteriaData",
          querySupplierList: "/ghSupplychainSupplier/allList",
          queryDepositoryList: "/ghSupplychainDepository/allList",
          queryUserList: "/sys/user/allList",
        },
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },
        totalPrice: 0,
        dictOptions: {},
        superFieldList: [],
        currentReceiptsType: 0,
        currentReceiptsDate: '',
        currentOrderStatus: 0,
        receiptsTypeList: [],  //搜索条件：单据类型
        receiptsDateList: [],  //搜索条件：单据时间
        orderStatusList: [],   //搜素条件：订单状态
      }
    },
    created() {
      this.initSearchConditionData();
      /*this.loadUserListData();
      this.loadSupplierData();
      this.loadDepositoryData();*/
      //this.loadData();
    },
    methods: {
      initSearchConditionData() {
        getAction(this.url.getSearchConditionData).then(res => {
          if (res.success) {
            this.receiptsTypeList = res.result.receiptsTypeList;
            this.receiptsDateList = res.result.receiptsDateList;
            this.orderStatusList = res.result.orderStatusList;
          }
        })
      },
      //自定义单据时间
      onChangeCustomerReceiptsDate(value, dateString){
        this.startDate = dateString[0];
        this.endDate = dateString[1];
        this.currentReceiptsDate = "customizeTime";
        this.loadData(1);
      },
      //单据时间发生变化
      onChangeReceiptsDate(key, itemValue) {
        for (let i = 0; i < this.receiptsDateList.length; i++) {
          if (key == this.receiptsDateList[i].key) {
            this.receiptsDateList[i].checkedValue = true;
          } else {
            this.receiptsDateList[i].checkedValue = false;
          }
        }
        if (key == 'key9') {
          this.currentKey = true;
        } else {
          this.currentKey = false;
          this.dateValue = [];
          this.currentReceiptsDate = itemValue;
          this.loadData(1);
        }
      },
      loadData(arg) {
        //var params = this.model;//查询条件
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件

        if (this.model.supplierName != null && this.model.supplierName != "") {
          params.supplierName = this.model.supplierName;
        }
        if (this.model.depositoryName != null && this.model.depositoryName != "") {
          params.depositoryName = this.model.depositoryName;
        }
        if (this.model.purchasePeople != null && this.model.purchasePeople != "") {
          params.purchasePeople = this.model.purchasePeople;
        }
        if (this.model.createBy != null && this.model.createBy != "") {
          params.createBy = this.model.createBy;
        }

        if (this.currentReceiptsType != null && this.currentReceiptsType != '' && this.currentReceiptsType != 0) {
          params.receiptsType = this.currentReceiptsType;
        } else {
          params.receiptsType = "";
        }

        if (this.currentReceiptsDate != null && this.currentReceiptsDate != '') {
          params.currentReceiptsDate = this.currentReceiptsDate;
          if (this.currentReceiptsDate == "customizeTime") {
            params.beginTime = this.startDate;
            params.endTime = this.endDate;
          }
        } else {
          params.currentReceiptsDate = "";
        }

        if (this.currentOrderStatus != null && this.currentOrderStatus != '' && this.currentOrderStatus != 0) {
          params.orderStatus = this.currentOrderStatus;
        } else {
          params.orderStatus = "";
        }
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result;
            this.totalPrice = 0;
            for (let i = 0; i < this.dataSource.length; i++) {
              this.totalPrice += this.dataSource[i].subtotal;
            }
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
    },
  }
</script>

<style scoped>

</style>